package chapter7;

public class People implements Comparable<People> {

    public String id;
    public String name;
    public boolean sex;
    public int age;


    public People(String id, String name, boolean sex, int age) {
        this.id = id;
        this.name = name;
        this.sex = sex;
        if (age < 1 || age > 100) {
            this.age = 18;
        }
        this.age = age;
    }

    public void setId(String id) {
        this.id = id;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setSex(boolean sex) {
        this.sex = sex;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getId(){
        toString("id: "+this.id);
        return this.id;
    }

    public String getName(){
        toString("name: "+this.name);
        return this.name;
    }

    public boolean getSex(){
        toString("sex: "+this.sex);
        return this.sex;
    }

    public int getAge(){
        toString("age: "+this.age);
        return this.age;
    }

    public int compareTo(People that) {
        if (this.age < that.age) return -1;
        else if (this.id.compareTo(that.id) < 1) return -1;
        else if (this.age > that.age) return 1;
        else if (this.id.compareTo(that.id) > 1) return 1;
        else return 0;
    }

    public void toString(String arg) {
        System.out.println(arg);
    }
}
